package cytargetlinker.actions;

import java.awt.event.ActionEvent;
import java.util.Set;

import javax.swing.JOptionPane;

import cytargetlinker.CyTargetLinker;
import cytargetlinker.CyTargetLinkerPlugin;
import cytoscape.CyNetwork;
import cytoscape.Cytoscape;
import cytoscape.util.CytoscapeAction;

/**
 * opens the plugin dialog to load the interaction networks
 */
public class LoadInteractionsAction extends CytoscapeAction {
	
	private CyTargetLinkerPlugin plugin;

	public LoadInteractionsAction(CyTargetLinkerPlugin plugin) {
		this.plugin = plugin;
		super.initialize();
		putValue(NAME, "Load Regulatory Interaction Networks");
		setPreferredMenu("Plugins");
	}
		
	@Override
	public void actionPerformed(ActionEvent arg0) {
		Set<CyNetwork> networks = Cytoscape.getNetworkSet();
		
		/**
		 * at least one network has to be open
		 */
		if (networks != null && networks.size() > 0) {
			CyTargetLinker linker = new CyTargetLinker(plugin);
			linker.openDialog();
		} else {
			JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "No network in current session.", "Warning", JOptionPane.WARNING_MESSAGE);
		}
	}
		
}